﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Windows.Media.Animation;
using System.Collections;

namespace PRScreenWithKinect.UI
{
    /// <summary>
    /// Interaction logic for Menu.xaml
    /// </summary>
    public partial class Menu : UserControl
    {
       Storyboard stSlideUp;
        Storyboard stSlideDown; 
        private Boolean isToggle = false;
        private ArrayList controllerElement;
        private UIElement hitElement = null;
        private MainWindow main; 
        public Boolean IsToggle
        {
            get { return isToggle; }
            set { isToggle = value; }
        }

        public Menu(MainWindow m )
        {
            InitializeComponent();
            //// Set MainWindow 
            main = m;


            //// Hidden when insert 
            this.Visibility = Visibility.Hidden;

            /// Initial controllerElement Array 

            controllerElement = new ArrayList();
            controllerElement.Add(_PR_CE);
            controllerElement.Add(_Gallery_CE);
            controllerElement.Add(_Location_CE);
            controllerElement.Add(_AboutFac_CE);
            controllerElement.Add(_GuestBook_CE);
            controllerElement.Add(_Help_CE);

            /// Create Slide up & down event
            /// 

            stSlideDown= (Storyboard)this.Resources["slideDownFX"];
            Storyboard.SetTarget(stSlideDown.Children[0], this);
            Storyboard.SetTargetProperty(stSlideDown.Children[0], new PropertyPath("(UIElement.RenderTransform).(TransformGroup.Children)[0].(TranslateTransform.Y)"));

            stSlideUp = (Storyboard)this.Resources["slideUpFX"];
            Storyboard.SetTarget(stSlideUp.Children[0], this);
            Storyboard.SetTargetProperty(stSlideUp.Children[0], new PropertyPath("(UIElement.RenderTransform).(TransformGroup.Children)[0].(TranslateTransform.Y)"));
           

        }

        void stSlideUp_Completed(object sender, EventArgs e)
        {
            this.Visibility = Visibility.Hidden;
        }
        public void slideDown() 
        {
            this.Visibility = Visibility.Visible;
           stSlideDown.Begin();
            isToggle = !isToggle;
        }
        public void slideUp()
        {
            stSlideUp.Begin();
           // this.Visibility = Visibility.Hidden;
            isToggle = !isToggle;
        }
        
        public Boolean hitTest(Point p,Window m)
        {
      
            Boolean isHit = false;
            foreach (UIElement c in controllerElement)
            {
                Point RhandRelativePoint = c.TransformToAncestor(m).Transform(new Point(0, 0));
                Point delta = new Point(p.X -RhandRelativePoint.X, p.Y - RhandRelativePoint.Y);
                if (VisualTreeHelper.HitTest(c, delta) != null)
                {
                    isHit = true;
                    hitElement = c;
                    break;
                }
            }
            return isHit;
            
        }
        public void finishHold()
        {
           StackPanel h = (StackPanel)hitElement ;
            String name = h.Name ;
            if (name.Equals("_PR_CE"))
            {
                main.openContent("News");
            }
            else if(name.Equals("_Gallery_CE"))
            {
                main.openContent("Gallery");
            }else if(name.Equals("_Location_CE"))
            {
                main.openContent("Location");
            }else if(name.Equals("_AboutFac_CE"))
            {
                main.openContent("AboutFac");
            }
            else if (name.Equals("_GuestBook_CE"))
            {
                main.openContent("GuestBook");
            }
            else if (name.Equals("_Help_CE"))
            {
                main.openContent("Help");
            }
        }
    }
}
